<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<script
			src="https://www.paypal.com/sdk/js?client-id=ATGjtjTpMF8QAyZRWKoLzD8qTPdWGlMBk4r950mgh0R6wHi7ss4K4EwBwra38gTQB0pVgu1soz4uuEE8">
		</script>
		<title></title>
	</head>
	<body>
		<script>
			function setPaypal() {
				paypal
					.Buttons({
						 // style: {
						 //    layout: 'vertical',
						 //    color:  'blue',
						 //    shape:  'rect',
						 //    label:  'paypal'
						 //  },
						createOrder: function(data, actions) {
							// 定义一下要付多少钱
							console.log('createOrder')
							return actions.order.create({
								purchase_units: [{
									reference_id: "order_id",
									amount: {
										value: "0.03"
									}
								}]
							});
						},
						onApprove: function(data, actions) {
							// console.log(data,actions)
							return actions.order.capture().then(function(details) {
								// 付款成功之后的回调
								alert(
									"Transaction completed by " + details.payer.name.given_name
								);
								// 告诉你自己的服务器订单号,方便后续的查询
								console.log('执行跳转')
								return fetch("/paypal-transaction-complete", {
									method: "post",
									headers: {
										"content-type": "application/json"
									},
									body: JSON.stringify({
										orderID: data.orderID
									})
								});
							});
						}
					})
					.render("#paypal-button");
				// 把付款按钮放id为app的盒子里
			}
			setPaypal()
		</script>
		<div id="paypal-button"><!--app-html--></div>
	</body>
</html>